//
//  AYMLoadWatherMessage.m
//  QuickCure
//
//  Created by 张聪 on 16/5/9.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMLoadWatherMessage.h"
#import "AYMHomeController.h"
#import "AYMWeatherModel.h"
#import "AYMWeatherView.h"
#import "AYMMainWeatherModel.h"

@implementation AYMLoadWatherMessage

+ (void)loadWeatherWithCity:(NSString *)city andViewController:(AYMHomeController *)vc {
    //发送请求
    NSString *urlString = @"http://api.map.baidu.com/telematics/v3/weather?";
    
    //参数
    NSDictionary *parameters = @{
                                 @"location" : city,
                                 @"output" : @"json",
                                 @"ak" : @"17IvzuqmKrK1cGwNL6VQebF9"
                                 };
    
    
    
    [[AYMNetworkTool sharedManager] request:RequestMethodGet urlString:urlString parameters:parameters finished:^(id responseObject, NSError *error) {
        
        Log(@"%@",responseObject);
        //判断有没有网络
        if (responseObject) {
            
            for (NSDictionary *dict in responseObject[@"results"]) {
                
                AYMMainWeatherModel *model = [AYMMainWeatherModel yy_modelWithJSON:dict];
                
                
                [vc.weatherView reloadDatas:model];
                
                
            }
            
            AYMWeatherModel *model = [AYMSQLiteManager queryWeather].lastObject;
            
            if (model.date) {
                
                vc.weatherModel = model;
            }
        }
    }];
}


@end
